package com.vates.curso.dao.imp;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.vates.curso.dao.UserDao;
import com.vates.curso.entities.User;

@Repository("userDao")
public class UserDaoImp extends GenericDaoHibernate<User, Long> implements
		UserDao {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.vates.practicofinal.dao.hibernate.BaseDao#getRelatedEntityClass()
	 */
	public Class<User> getRelatedEntityClass() {
		return User.class;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.vates.practicofinal.dao.hibernate.UserDao#getUserByName(java.lang
	 * .String)
	 */
	public User getUserByName(String userName) {
		if (userName == null) {
			return null;
		}
		List<User> list = executeSQLQuery("from User u where u.userName='"
				+ userName + "'");
		if (list.size() == 1) {
			return list.get(0);
		}
		return null;
	}

}